// useEffect清除副作用
import { useEffect, useState } from "react";

function Son () {
  // 渲染一个定时器
  useEffect(() => {
    const timer = setInterval(() => {
      console.log("son");
    }, 1000);
    return () => {
      console.log("son 销毁");
      clearInterval(timer);
    }
  }, []);
  return (
    <div>
      <h1>son</h1>
    </div>
  )
}
function App() {
  const [show, setShow] = useState(true);

  return (
    <div>
      {show && <Son />}
      <button onClick={() => {
        setShow(!show);
      }}>点击切换</button>
    </div>
  )
}
export default App; 